﻿using System.Linq;
using TmU220PrintHelperV2d0.Entity;
using TmU220PrintHelperV2d0.Service;

namespace TmU220PrintHelperV2d0.Singleton
{
    public class ApiRouterMethodSetSingletonV1d0
    {
        private static ApiRouterMethodSetSingletonV1d0 _instance = null;
        private ApiRouterMethodSetV1d0 _apiRouterMethodSet = null;
        private static readonly object syslock = new object();
        /// <summary>
        /// 单例模式
        /// </summary>
        public static ApiRouterMethodSetSingletonV1d0 Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (syslock)
                    {
                        if (_instance == null)
                        {
                            _instance = new ApiRouterMethodSetSingletonV1d0();
                        }
                    }
                }
                return _instance;
            }
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        private ApiRouterMethodSetSingletonV1d0()
        {
            _apiRouterMethodSet = new ApiRouterMethodSetV1d0();
            LoadData();
        }
        /// <summary>
        /// 装载数据
        /// </summary>
        private void LoadData()
        {
            string currDir = System.IO.Directory.GetCurrentDirectory();
            string filename = currDir + @"\parameter\apiRouterMethodSet.xml";
            _apiRouterMethodSet = HotchPotchV2d0.ReadFromXmlFile<ApiRouterMethodSetV1d0>(filename);
        }
        public ApiRouterMethodV1d0 GetApiRouterMethod(string methodName)
        {
            ApiRouterMethodV1d0 routerMethod = null;
            routerMethod = _apiRouterMethodSet.ApiRouterMethodList.FirstOrDefault(x => x.MethodName == methodName);
            return routerMethod;
        }
    }
}
